// pages/myBankCard/myBankCardAdd.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    select: false,
    tihuoWay: '门店自提'
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    //获取手机高度
    this.setData({
      navT: app.globalData.navTop,
      navLH: app.globalData.navLineHeight,
      navH: app.globalData.navHeight,
      modelmes: app.globalData.modelmes
    })
    var that = this;
    wx.request({
      url: app.globalData.url + "getParaById?paraId=quit_community_head_cause",
      method: "GET",
      data: {
      },
      success: function (res) {
        if (res.data.result == 1) {
          var str = res.data.data.value.split("#");
          that.setData({
            value: str,
            tihuoWay: str[0]
          })
        } else {

        }
      }
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.setData({
      token: wx.getStorageSync("token")
    });
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  
  name: function (e) {
    this.setData({
      realname: e.detail.value,
    })
  },
  iphone: function (e) {
    this.setData({
      telephone: e.detail.value,
    })
  },
  navBack: function () {
    wx.navigateBack({

    })
  },
  bindShowMsg() {
    this.setData({
      select: !this.data.select
    })
  },
  mySelect(e) {
    var value = e.currentTarget.dataset.value
    this.setData({
      tihuoWay: value,
      select:false
    })
  },

  //提交申请
  submit: function(){
    var that = this;
    if (that.data.realname == undefined || that.data.realname == '') {
      wx.showToast({
        title: '请填写姓名',
        icon: 'none',
      });
      return false;
    }
    if (that.data.telephone == undefined || that.data.telephone == '') {
      wx.showToast({
        title: '请填写手机号',
        icon: 'none',
      });
      return false;
    }
    wx.request({
      url: app.globalData.url + "cancelUserHeadWeChat",
      data: {
        userId: wx.getStorageSync("userId"),
        cause: that.data.tihuoWay,
        realname: that.data.realname,
        telephone: that.data.telephone,
      },
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        if (res.data.result == 1) {
          setTimeout(function () { // 做了个延时重试一次，作为保底。
            wx.showToast({
              title: '申请成功，请等待审核！',
              icon: "none",
              duration: 2000,      //停留时间
            })
          }, 500)
          wx.navigateBack({
            
          })
        } else {
          wx.showToast({
            title: res.data.errmsg,
            icon: 'none',
          });
        }
      },
    })
  },
})